package com.everflourish.yeah100.utils;

import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;

import com.everflourish.yeah100.R;

/**
 * 作者：Created by liqisi on 2016/9/6.
 * 时间：2016/9/6
 */
public class VersionUtil {

    public static final String APP_NAME = "易100";
    private static final String TAG = "VersionUtil";

    /**
     * 目前的客户端的版本号
     *
     * @param context
     * @return
     */
    public static int getVersionCode(Context context) {
        int verCode = -1;
        try {
            String p = context.getPackageName();
            verCode = context.getPackageManager().getPackageInfo(p, 0).versionCode;
        } catch (NameNotFoundException e) {
            Log.e(TAG, e.getMessage());
        }
        return verCode;
    }

    /**
     * 目前的客户端的版本名称
     *
     * @param context
     * @return
     */
    public static String getVersionName(Context context) {
        String verName = "";
        try {
            verName = context.getPackageManager().getPackageInfo(
                    context.getPackageName(), 0).versionName;
        } catch (NameNotFoundException e) {
            Log.e(TAG, e.getMessage());
        }
        return verName;

    }

    /**
     * 应用名称
     *
     * @param context
     * @return
     */
    public static String getAppName(Context context) {
        String verName = context.getResources().getText(R.string.app_name)
                .toString();
        return verName;
    }
}